function renderScore() {
  //发送axios  请求数据
  axios({
    url: "/score/list",
    method: "get",
    //data: { 'post请求参数'},
    // params: { 'get请求参数'}
  }).then(({ data: res }) => {
    if (res.code == 0) {
      //成功回调
      //自己定义一个数组
      let arr = [];
      //遍历对象
      for (let k in res.data) {
        arr.push(
          ` <tr>
          <th scope="row">${k}</th>
          <td>${res.data[k].name}</td>
          <td  data-id="${k}" data-batch="1"  class="score">${res.data[k].score[0]}</td>
          <td  data-id="${k}" data-batch="2"  class="score">${res.data[k].score[1]}</td>
          <td  data-id="${k}" data-batch="3"  class="score">${res.data[k].score[2]}</td>
          <td  data-id="${k}" data-batch="4"  class="score">${res.data[k].score[3]}</td>
          <td  data-id="${k}" data-batch="5"  class="score">${res.data[k].score[4]}</td>
        </tr>
           `
        );
      }
      document.querySelector("tbody").innerHTML = arr.join("");
      // console.log(res);
    }
  });
}

renderScore();

//需求3:修改学生信息
document.querySelector("tbody").onclick = function (e) {
  //判断点击是否是当前成绩
  if (!e.target.classList.contains("score")) return;
  //自己创建一个input 标签
  let input = document.createElement("input");
  //把点击的input  标签赋值给 自己添加input
  input.value = e.target.innerHTML;
  e.target.innerHTML = "";
  //添加到input标签
  e.target.appendChild(input);

  //失去焦点恢复原值
  let txt = input.value; //获取input的值
  //input  注册焦点事件
  input.onblur = function () {
    //失去焦点修改td中值
    e.target.innerHTML = txt;
  };

  //自动获取光标
  input.focus();
  //修改成绩
  input.onkeyup = function (e) {
    if (e.key != "Enter") return;
    //发送axios
    axios({
      url: "/score/entry",
      method: "post",
      data: {
        stu_id: this.parentNode.getAttribute("data-id"),
        batch: this.parentNode.getAttribute("data-batch"),
        score: this.value,
      },
    }).then(({ data: res }) => {
      //判断业务状态码
      if (res.code == 0) {
        //给个提示
        toastr.success("修改信息成功");
        //刷新页面
        renderScore();
      }
      //成功回调
      console.log(res);
    });
  };
};
